package svc.elib.socnet;

import java.io.IOException;
import java.util.Iterator;
import java.util.Scanner;

import svc.elib.db.Author;
import svc.elib.db.Database;

/**
 * Social network explorer
 * 
 * @author svc
 * @date 9.6.2012
 */
public class Explorer {

	public static void main(String[] args) 
		throws IOException
	{
		Database db = new Database("eLibData.csv", 1932, 2011);
		SocConstructor soc = new SocConstructor(db);
		Net net = soc.getNet();
		net.printInfo();
		
		Scanner in = new Scanner(System.in);
		while (true) {
			System.out.println("\nEnter first name (or exit): ");
			String firstName = in.nextLine();
			if (firstName.compareTo("exit") == 0)
				break;
			
			System.out.println("Enter last name: ");
			String lastName = in.nextLine();
			
			Author a = db.searchAuthor(firstName, lastName);
			if (a != null) {
				a.printFullInfo();
				
				System.out.println("Direct connections... ");
				Iterator<Author> ait = net.getGraph().getNeighbors(a).iterator();
				while (ait.hasNext()) {
					Author nei = ait.next();
					System.out.println(nei.getName());
				}
				
				ConnectedComponents compFilter = new ConnectedComponents(net);
				Net comp = compFilter.resolveComponent(a, 1);
				System.out.println("Component of author... ");
				comp.printInfo();
				System.out.println("Authors in connected component...");
				comp.dumpAuthors();
				TrivialComponents tc = new TrivialComponents(net);
				if (tc.isTrivial(comp)) {
					System.out.println("-- Trivial component");
				} else {
					System.out.println("-- Non-trivial component");
				}
			} else {
				System.out.println("Author does not exsist");
			}
		}
		
		in.close();
	}
	
}
